package com.Javatest4;

import javax.net.ssl.HostnameVerifier;
import java.util.ArrayList;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ArrayList<Animal> AnimalList = new ArrayList<Animal>();
        AnimalTest At = new AnimalTest();
        System.out.println("输入Type, Name, color, age(Cat)");
        for(int i = 0; i < 3; i ++ ){
            String t, n, c;
            int a;
            t = in.next();
            n = in.next();
            c = in.next();
            a = in.nextInt();
            Cat cat = new Cat(t, n, c, a);
            At.Push_back(cat);
        }

        System.out.println("输入Type, Name, Color, Height(Horse)");
        for(int i = 0; i < 3; i ++ ){
            String t, n, c;
            double h;
            t = in.next();
            n = in.next();
            c = in.next();
            h = in.nextDouble();
            Horse hor = new Horse(t, n, c, h);
            At.Push_back(hor);
        }

        At.Output();
    }
}

class AnimalTest{
    private ArrayList<Animal> list = new ArrayList<Animal>();

    public void Output(){
        for(Animal animal : list){
            if(animal instanceof Cat){
                System.out.println("          Cat          ");
                System.out.println(((Cat) animal).to_String());
            }
            else if(animal instanceof Horse){
                System.out.println("          Horse         ");
                System.out.println(((Horse) animal).to_String());
            }
            animal.sleep();
            animal.wakeUp();
            animal.walk();
        }
    }

    public void Push_back(Animal a){
        list.add(a);
    }
}

class Horse extends Animal{
    private double height;

    Horse(){}
    Horse(String t, String n, String c, double h){
        super(t, n, c);
        this.height = h;
    }

    @Override
    public void sleep(){
        System.out.println("The horse is sleeping!");
    }

    @Override
    public void wakeUp(){
        System.out.println("The horse wakes up!");
    }

    @Override
    public void walk(){
        System.out.println("The horse is walking and shouting.");
    }

    public String to_String(){
        return "Type:" + this.getType() + " Name:" + this.getName() + " Color:" + this.getColor() + " Height:" +
                + this.getHeight() + "m";
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
}

class Cat extends Animal{
    private int age;

    Cat(){}
    Cat(String t, String n, String c, int a){
        super(t, n, c);
        this.age = a;
    }

    @Override
    public void sleep(){
        System.out.println("The cat is sleeping!");
    }

    @Override
    public void wakeUp(){
        System.out.println("The cat wakes up!");
    }

    @Override
    public void walk(){
        System.out.println("The cat is walking silently.");
    }

    public String to_String(){
        return "Type:" + this.getType() + " Name:" + this.getName() + " Color:" + this.getColor() + " Age:" +
                + this.getAge() + "Months";
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

abstract class Animal{
    private String type, name, color;

    Animal() {}
    Animal(String t, String n){
        this.type = t;
        this.name = n;
    }
    Animal(String t, String n, String c){
        this(t, n);
        this.color = c;
    }

    abstract void sleep();

    abstract void wakeUp();

    abstract void walk();

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}
